/************************************************************************
This file is part of Polar4linux
Copyright (C) 2010-2011 Eric jrdn2
Portions Copyright (C) 2007 Matti Juvonen <mpj@iki.fi> (RS400 Tools)
Portions Copyright (C) 2006 Jani Hursti <jani.hursti@hut.fi>,
Portions Copyright (C) 2001-2003 Tom Oliveira e Silva

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
************************************************************************/

#include "iftwidget.h"
#include <iostream>

IFTwidget::IFTwidget( QWidget *parent, const char* /* name*/ ): QWidget( parent )
{
	setupUi(this);
	setStyle(noneDisplay);
}

IFTwidget::~IFTwidget()
{
	;
}

void IFTwidget::setStyle(int _style)
{
	style=_style;
	if (style==intDisplay)
	{
		SpinBoxDouble->setVisible(false);
		SpinBoxTime->setVisible(false);
		spinBoxInt->setVisible(true);
	}
	else if (style==floatDisplay)
	{
		spinBoxInt->setVisible(false);
		SpinBoxTime->setVisible(false);
		SpinBoxDouble->setVisible(true);
	}
	else if (style==timeDisplay)
	{
		spinBoxInt->setVisible(false);
		SpinBoxDouble->setVisible(false);
		SpinBoxTime->setVisible(true);
	}
	else
	{
		spinBoxInt->setVisible(false);
		SpinBoxDouble->setVisible(false);
		SpinBoxTime->setVisible(false);
	}
}

void IFTwidget::setValue(int left,int right)
{
	if (style==intDisplay)
	{
	  spinBoxInt->setValue(left);
	}
	else if (style==floatDisplay)
	{
	  SpinBoxDouble->setValue(left+right/100.0);
	}
	else if (style==timeDisplay)
	{
	  SpinBoxTime->setTime(QTime(0,left,right));
	}
	else
	{
	  //nothing
	}
}

int IFTwidget::valueLeft() const
{
	if (style==intDisplay) return spinBoxInt->value();
	else if (style==floatDisplay) return SpinBoxDouble->value();
	else if (style==timeDisplay) return SpinBoxTime->time().minute();
	else return 0;
}


int IFTwidget::valueRight() const
{
  if (style==intDisplay) return 0;
  else if (style==floatDisplay) return (100* (SpinBoxDouble->value()-(int)SpinBoxDouble->value()));
  else if (style==timeDisplay) return SpinBoxTime->time().second();
  else return 0;
}

